/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../../server/Channel.h"
#include "../../server/Map.h"
#include "PartyMembers.h"
#include "PartyMember.h"
#include "../../server/Player.h"

PartyMembers::~PartyMembers() {
	for(hash_map <int, PartyMember*>::iterator iter = members.begin(); iter != members.end(); iter++) {
		delete iter->second;
	}
}

void PartyMembers::addMember(Player* player) {
	add(player);
	PartyMember* member = new PartyMember();
	member->setID(player->getID());
	member->setJob(player->getJob());
	member->setLevel(player->getLevel());
	member->setChannel(player->getChannel()->getID());
	member->setMap(player->getMap()->getID());
	member->setName(player->getName());
	addMember(member);
}

void PartyMembers::addMember(PartyMember* member) {
	if(members.find(member->getID()) != members.end()) {
		delete members[member->getID()];
	}
	members[member->getID()] = member;
}

void PartyMembers::deleteMember(int id) {
	delete members[id];
	members.erase(id);
	players.erase(id);
}

void PartyMembers::removeMember(int id) {
	members[id]->setChannel(-2);
	members[id]->setMap(999999999);
	players.erase(id);
}